package com.xuya.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.xuya.dao.AdminerDao;
import com.xuya.entity.Adminer;

public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String name = req.getParameter("username");
		String pwd = req.getParameter("pwd");
		if(name == null |"".equals(name)|pwd== null|"".equals(pwd)){
			resp.sendRedirect("index.jsp?code=10001");
			return;
		}
		AdminerDao dao = new AdminerDao();
		Adminer adminer =dao.findByName(name);
		if(adminer != null && adminer.getName().equals(name) && adminer.getPwd().equals(pwd)){
			HttpSession session = req.getSession();
			session.setAttribute("user",adminer);
			resp.sendRedirect("home.jspx");
			return;
		}else{
			resp.sendRedirect("WEB-INFindex.jsp?code=10002");	
		}
	}

}
